#!/bin/sh

fromext="$1"
toext="$2"

usage () {
  echo "Usage: $0 fromext toext"
  echo "Example: $0 htm html"
}

if [ -z "$1" ] || [ -z "$2" ]
then
  echo "Too few arguments."
  usage
  exit 0
fi
if [ -n "$3" ]
then
  echo "Too many arguments."
  usage
  exit 0
fi

filelist=`find . -type f -name "*.$fromext"`

changeext () {
  while read file
  do
    newname=`echo "$file" | sed "s/\(.*\.\)${fromext}$/\1$toext/"`
    mv "$file" "$newname"
  done
}

if [ -n "$filelist" ]
then
  echo "$filelist" | changeext
else
  echo "No files to process."
fi


exit 0